package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

/**
 * @author ZZQ
 * @PackageName: com.neutech.maplestory.entity
 * @ClassName: Power
 * @Description:
 * @date 2021/1/30 13:20
 */
public class Power extends AbstractMapleStoryObject{
    public static Image[] imgs = new Image[10];
    static{
        for(int i = 0;i < 10;i ++ ){
            imgs[i] = ImageUtil.getImage("power" + i);
        }
    }
    public Power(){
        this.speed = 5;
        this.live = true;
    }

    /**
     * 每一个伤害值
     */
    public int value;

    public Power(MapleStoryClient msc,int x,int y){
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
//        this.speed = 5;
        this.value = msc.hero.hitValue;
//        this.live = true;
    }
    @Override
    public void draw(Graphics g) {
        if(!live){
            msc.powers.remove(this);
            return;
        }
        drawValue(g);
//        Font f = g.getFont();
//        g.setFont(new Font("微软雅黑",Font.BOLD,60));
//        g.drawString(value + "",x,y);
//        g.setFont(f);
        move();
    }
    /**
     * 使用图片画伤害值
     * @param g 画笔
     */
    public void drawValue(Graphics g){
        int power = this.value;//1728
        if (power >= 9999){
            power = 9999;
        }
        int units = power % 10;//8
        power = power / 10;//172
        int tens = power % 10;//2
        power = power / 10;//17
        int hundreds = power % 10;//7
        power = power / 10;//1
        int thousands = power;
        if (tens == 0 && hundreds == 0 && thousands ==0 ){
            //只画个位
            g.drawImage(imgs[units],x,y,null);
        }
        if (hundreds == 0 && thousands == 0 && tens != 0){
            //画十位
            g.drawImage(imgs[tens],x,y,null);
            //画个位
            g.drawImage(imgs[units],x + 30,y,null);
        }
        if (hundreds != 0 && thousands == 0 ){
            //画百位
            g.drawImage(imgs[hundreds],x,y,null);
            //画十位
            g.drawImage(imgs[tens],x + 30,y,null);
            //画个位
            g.drawImage(imgs[units],x + 60,y,null);
        }
        if (thousands != 0 ){
            //画千位
            g.drawImage(imgs[thousands],x,y,null);
            //画百位
            g.drawImage(imgs[hundreds],x + 30,y,null);
            //画十位
            g.drawImage(imgs[tens],x + 60,y,null);
            //画个位
            g.drawImage(imgs[units],x + 90,y,null);
        }

    }

    @Override
    public void move() {
        if(this.y <= 400){
            this.live = false;
        }
        this.y -= speed;
    }
}


